home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-03-19 | 27.9 KB | 731 lines | [TEXT/MPS ] |
- #########################################################################
- #########################################################################
- ## Copyright © Apple Computer, Inc. 1993-1997
- ## All rights reserved
- #########################################################################
- #########################################################################
- ##
- ##
- ## WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
- ##
- ## THIS LIBRARY IS OBSOLETE. IT IS INCLUDED FOR BACKWARDS COMPATIBILITY.
- ##
- ## IT WILL BE REMOVED IN FUTURE RELEASES OF THE CLOUSEAU LIBRARIES.
- ##
- ## DO NOT USE THIS LIBRARY IN NEW SCRIPTS.
- ##
- ## Use ExceptionHandling.lib in the SPEC Libraries instead of Errors.lib.
- ##
- ##
- #########################################################################
- #########################################################################
- # Library: Errors.lib
- #
- # Version: 2.1.4
- #
- # Description:
- # Contains tasks for script errors.
- #
- # Contains:
- # ErrorHandler()
- # EPushHandler()
- # EPopHandler()
- # EGetHandler()
- # EClearCurrentError()
- # ESuspendCurrentError()
- # EResumeCurrentError()
- # _match()
- # _select()
- # _type()
- # _pressKey()
- # _releaseKey()
- # E_InitializeErrors()
- #
- # History:
- # Date: By: Changes:
- # 06/15/93 SBR Created for use with Launchquits (LQ Project)
- # 02/19/94 SBR Moved to Clouseau Project for everyone to use
- # 05/25/94 SBR Optimized _match(), added _matchBoolean()
- # 01/21/97 SBR Updated copyright header.
- #
- #########################################################################
- #########################################################################
-
- Libraries
- "Report.lib";
-
- #######################################################################################
- # task ErrorHandler(errorIn, notErrors, v_level)
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # Description: Handle serious errors from the ScriptError() built-in task. A serious
- # error is one which causes script flow to change unexpectedly to
- # handle global problems like target crashes. The caller determines
- # which errors are serious by using the notErrors parameter, and what
- # to do for each error by pushing and popping items on the error
- # handler stack. You can simulate errors by passing values directly.
- # This task is designed for use by a VU library's primitives.
- # Parameters: errorIn: The result of ScriptError() for a command statement.
- # Note: You can not call ScriptError() inside a task to check the
- # statement which preceded the task call. If you do, ScriptError()
- # returns zero because there was no error entering the task.
- # notErrors: A list of error codes which should not be considered
- # serious errors this time. E.g.: for _match(), -1105 is a
- # simple match failure. Script flow continues, _match
- # returns [] and whoever called _match will handle it.
- # Returns: { errorValue, errorString }
- # Examples: theError := ErrorHandler(ScriptError(), {-1105});
- # Assumptions: VU 2.0.1 (VU 2.1 desired for -1096 error handling, but not required)
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # History:
- # 06/12/93 SBR Created
- # 10/14/93 SBR Fixed major bug by using gErrorsAreInitialized flag
- # 03/11/95 SBR Added -1096 string
- #######################################################################################
- task ErrorHandler(theError := 0, notErrors := {}, v_level := 4)
- begin
- global gCurrentError, g_Trap_NoError, gErrorsAreInitialized;
-
- RStatus("ErrorHandler: theError: {theError}", v_level);
-
- if not gErrorsAreInitialized
- E_InitializeErrors();
-
- if (not theError) and (not g_Trap_NoError) # optimized for speed
- return { 0,"no error" };
- else if isMember(theError, notErrors)
- return { 0,"error handling was supressed for {theError}" };
-
- if gCurrentError begin
- ESuspendCurrentError();
- pleaseResumeError := true;
- end;
-
- if theError = -1100 # It's Mr. Sluggo! Oh, noooo!!!!
- gCurrentError := {theError, "Target is crashed or disconnected"};
- else if theError = -1096 # VU 2.1 detected a new Agent "ID"
- gCurrentError := {theError, "Target restarted unexpectedly"};
- else
- gCurrentError := {theError, "unknown reason"};
-
- theHandler := EGetHandler(theError);
- if not theHandler
- theResult := {theError, "no handler or string exists for error value {theError}"};
- else begin
- theTask := theHandler[1];
- if theTask begin
- error_v_level := theHandler[3];
- if not error_v_level
- error_v_level := v_level;
- theResult := { theError,call(theTask, theError, theHandler[2], error_v_level) };
- end;
- else begin
- theString := theHandler[2];
- theResult := {theError, theString};
- end;
- end;
-
- if pleaseResumeError begin
- EResumeCurrentError();
- end;
-
- RStatus("ErrorHandler: theResult: {theResult}", v_level);
- return theResult;
- end;
-
-
- #########################################################################
- # task EPushHandler(theError, theHandler, v_level)
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # Description: Appends an item to the beginning of the global variable
- # gUserErrorVectorTable, so assoc() in EGetHandler() finds it first.
- # Parameters: theError: the key error value used by assoc to look up the handler
- # theHandler: the handler to execute; See the E_InitializeErrors()
- # routine for the format of an errorHandler.
- # v_level: Verbosity level for reporting
- # Returns: true if it worked, false if not
- # Examples: EPushHandler(-1100, { task crashRecover,{ "TeachText",1,5 }});
- # Assumptions: VU 2.0.1
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # History:
- # 06/12/93 SBR Created
- # 10/14/93 SBR Fixed major bug by using gErrorsAreInitialized flag
- #########################################################################
- task EPushHandler(theError, theHandler, v_level := 4)
- begin
- global gUserErrorVectorTable, g_Trap_NoError, gErrorsAreInitialized;
-
- if not gErrorsAreInitialized
- E_InitializeErrors();
-
- gUserErrorVectorTable := {{theError, theHandler}} + gUserErrorVectorTable;
-
- temp := ScriptError();
- if not temp begin
- if theError = 0 # handling No Error is weird - usually we skip it for speed
- g_Trap_NoError := true;
-
- return true;
- end;
- return RIncomplete("EPushHandler: ScriptError {theError} while pushing {theHandler}", v_level);
- end;
-
-
- #########################################################################
- # task EPopHandler(theError, v_level)
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # Description: Remove an item from the global variable gUserErrorVectorTable. See
- # the E_InitializeErrors() routine for the format of an item. If an
- # item already exists for that error it is replaced.
- # Parameters: errorHandler: the item to put in the list
- # v_level: Verbosity level for reporting
- # Returns: true if set worked, false if not
- # Examples: EPopHandler(-1100);
- # Assumptions: VU 2.0.1
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # History:
- # 06/12/93 SBR Created
- # 10/14/93 SBR Fixed major bug by using gErrorsAreInitialized flag
- #########################################################################
- task EPopHandler(theError, v_level := 4)
- begin
- global gUserErrorVectorTable, g_Trap_NoError, gErrorsAreInitialized;
-
- if not gErrorsAreInitialized
- E_InitializeErrors();
-
- theItem := assoc(theError, gUserErrorVectorTable);
- if not theItem
- return RIncomplete("EPopHandler: No handler exists for {theError}", v_level);
- else gUserErrorVectorTable :=
- remove(isMember({theError,theItem}, gUserErrorVectorTable), gUserErrorVectorTable);
-
- temp := ScriptError();
- if not temp begin
- if theError = 0
- if not assoc(0,gUserErrorVectorTable)
- g_Trap_NoError := false; # usually skip No Error for speed
- return true;
- end;
- return RIncomplete("EPopHandler: ScriptError {theError} while removing {theItem}", v_level);
- end;
-
-
- #########################################################################
- # task EGetHandler(theError, v_level)
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # Description: Get the handler for an error. Looks first in the global variable
- # gUserErrorStack, then in the global variable gErrorStack.
- # See the E_InitializeErrors() routine for the format of a handler item.
- # Parameters: theError: possible result from ScriptError() or any other value
- # v_level: Verbosity level for reporting
- # Returns: the item in the variable gErrorStack
- # Examples: theCrashString := EGetHandler(-1100)[2];
- # Assumptions: VU 2.0.1
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # History:
- # 06/12/93 SBR Created
- # 10/14/93 SBR Fixed major bug by using gErrorsAreInitialized flag
- #########################################################################
- task EGetHandler(theError, v_level := 4)
- begin
- global gErrorVectorTable, gUserErrorVectorTable, gErrorsAreInitialized;
-
- if not gErrorsAreInitialized
- E_InitializeErrors();
-
- theItem := assoc(theError, gUserErrorVectorTable);
- if theItem
- return theItem;
-
- theItem := assoc(theError, gErrorVectorTable);
- if theItem
- return theItem;
-
- RIncomplete("EGetHandler: {theError} is an unknown error",v_level);
- return {};
- end;
-
-
- #########################################################################
- # task EClearCurrentError(v_level)
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # Description: Since _match and the other super-primitives will not attempt target
- # communication if there is a current error, an error handler
- # which uses them must clear the error first. This task puts an empty
- # list into gCurrentError, and should only be called by the routine
- # that actually fixes the problem. To clear the current error
- # temporarily within a handler, call E_SuspendCurrentError() near the
- # beginning and E_ResumeCurrentError() near the end of your routine.
- # Parameters: v_level: Verbosity level for reporting
- # Returns: true
- # Examples: E_ClearCurrentError(); # this handler will fix the problem
- # Assumptions: VU 2.0.1
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # History:
- # 06/23/93 SBR Created
- #########################################################################
- task EClearCurrentError(v_level := 5)
- begin
- global gCurrentError;
-
- RStatus("EClearCurrentError: gCurrentError was {gCurrentError}", v_level);
- gCurrentError := {};
- end;
-
-
- #########################################################################
- # task ESuspendCurrentError(v_level)
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # Description: Since _match and the other super-primitives will not attempt target
- # communication if there is a current error, an error handler
- # which uses them must suspend the error first. This task pushes
- # gCurrentError onto the gPreviousErrorStack, and puts an empty
- # list into gCurrentError. When the handler is finished it
- # should call EResumeCurrentError().
- # NOTE: If a handler completely fixes the error it should
- # call EClearCurrentError() instead of ESuspendCurrentError()
- # and EResumeCurrentError().
- # Parameters: v_level: Verbosity level for reporting
- # Returns: true
- # Examples: ESuspendCurrentError();
- # Assumptions: VU 2.0.1, gPreviousErrorStack is initialized
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # History:
- # 06/23/93 SBR Created
- #########################################################################
- task ESuspendCurrentError(v_level := 5)
- begin
- global gCurrentError, gPreviousErrorStack;
-
- gPreviousErrorStack := {gCurrentError} + gPreviousErrorStack;
- RStatus("ESuspendCurrentError: gCurrentError was {gCurrentError}", v_level);
- gCurrentError := {};
- end;
-
-
- #########################################################################
- # task EResumeCurrentError(restoreIt, v_level)
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # Description: After calling ESuspendCurrentError(), an error handler task must
- # call EResumeCurrentError() so subsequent _match calls fail until
- # a higher level routine fixes the problem.
- # Parameters: restoreIt: true: Restore gCurrentError to its previous state.
- # Subsequent calls to _match (et al) will fail
- # until a routine solves the problem, then
- # calls EResumeCurrentError(false).
- # false: Pop the previous error off the stack, but
- # leave gCurrentError empty. Do not use false
- # until the problem has been completely fixed.
- # v_level: Verbosity level for reporting
- # Returns: true
- # Examples: EResumeCurrentError(true); # let someone else fix the problem
- # EResumeCurrentError(false); # we fixed the problem already
- # Assumptions: VU 2.0.1, gPreviousErrorStack is initialized
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # History:
- # 06/23/93 SBR Created
- #########################################################################
- task EResumeCurrentError(restoreIt, v_level := 5)
- begin
- global gCurrentError, gPreviousErrorStack;
-
- if gPreviousErrorStack begin
- temp := gPreviousErrorStack[1];
- gPreviousErrorStack := remove(1, gPreviousErrorStack);
- end;
- if restoreIt and temp
- gCurrentError := temp;
- else gCurrentError := {};
- RStatus("EResumeCurrentError: gCurrentError is now {gCurrentError}", v_level);
- end;
-
-
- #########################################################################
- # task _match(desc, exact, notErrors, v_level)
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # Description: Match a descriptor and handle any script errors. If target crashed,
- # always return [] until gCurrentError is reset.
- # Parameters: theDesc: the descriptor to match; add ! for exact
- # exact: true for exact (!)
- # notErrors: passed to ErrorHandler
- # v_level: verbosity level for reporting
- # Returns: same as match
- # Examples: theTarget := _match([target]);
- # myCheckBox := _match([checkBox o:3 w:2 s:{ 0,1 }], { true });
- # Assumptions: VU 2.0.1
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # History:
- # 06/12/93 SBR Created
- # 05/25/94 SBR Call ErrorHandler only if ScriptError <> 0 or -1105
- #########################################################################
- task _match(theDesc := [target], exact := false, notErrors := {-1105}, v_level := 4)
- begin
- if global gCurrentError begin
- RIncomplete("_match: current error ({gCurrentError}) - did not try match",v_level);
- return [];
- end;
-
- if exact theMatch := match theDesc!; # To ensure ScriptError() works, this statement
- else theMatch := match theDesc; # must not be first in the task.
-
- theError := ScriptError();
- if (theError = 0)
- return theMatch; # 0 = match occurred
- if (theError = -1105) AND isMember(-1105, notErrors)
- return theMatch; # -1105 = simple match failure
- else theError := ErrorHandler(theError, notErrors, v_level); # a real problem
-
- if R_BeVerbose(v_level) begin
- if theError[1]
- RIncomplete("_match: Error ({theError}) matching {theDesc}",v_level);
- else RStatus("_match: Matched {theDesc} with {theMatch}",v_level);
- end;
-
- return theMatch;
- end;
-
-
- #########################################################################
- # task _matchBoolean(desc, exact, notErrors, v_level)
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # Description: Match a descriptor quickly and return true or false. This is useful
- # with if statements, where you just want to know if the descriptor
- # exists. It uses VU optimization to save time when matching descriptors
- # that contain large lists, like control panel windows. Handles errors
- # just like _match, except if theError is -1105 it returns false. If
- # the target is crashed, return undefined until gCurrentError is reset.
- # Parameters: theDesc: the descriptor to match;
- # exact: true for exact (!) match
- # notErrors: passed to ErrorHandler only if error is not 0 or -1105
- # v_level: verbosity level for reporting
- # Returns: true if match worked (ScriptError() = 0),
- # false if not (ScriptError() = -1105),
- # undefined if ErrorHandler() returns an error
- # Examples: targetIsAlive := _matchBoolean([mouse]);
- # featureIsOff := _matchBoolean([checkBox o:3 w:2 s:{ 0,1 }], true);
- # Assumptions: VU 2.0.1
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # History:
- # 05/21/94 SBR Created
- # 09/03/94 SBR Changed exact default to true
- #########################################################################
- task _matchBoolean(theDesc, exact := true, notErrors := {}, v_level := 4)
- begin
- if global gCurrentError begin
- RIncomplete("_matchBoolean: current error ({gCurrentError}) - did not try match",v_level);
- return undefined;
- end;
-
- if exact
- match theDesc!; # To ensure ScriptError() works, this statement
- else
- match theDesc; # must not be first in the task.
-
- theError := ScriptError();
- if theError = 0
- return true; # no error, match occurred
- else if theError = -1105
- return false; # -1105 means simple match failure
- else theError := ErrorHandler(theError, notErrors, v_level); # a real problem
-
- if R_BeVerbose(v_level) begin
- if theError[1]
- RIncomplete("_matchBoolean: Error ({theError}) matching {theDesc}",v_level);
- else RStatus("_matchBoolean: Matched {theDesc} with {theMatch}",v_level);
- end;
-
- return undefined;
- end;
-
-
- #########################################################################
- # task _select(theDesc, exact, notErrors, v_level)
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # Description: Select a descriptor and handle any script errors. If target crashed,
- # always return false until gCurrentError is reset.
- # Parameters: theDesc: the descriptor to select; add ! for exact
- # exact: true for exact (!)
- # notErrors: passed to ErrorHandler
- # v_level: verbosity level for reporting
- # Returns: true/false for success/failure
- # NOTE: As of VU 2.0.1, the real select does not return a value
- # Examples: if not _select([menuItem 'Restart']) exit;
- # Assumptions: VU 2.0.1
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # History:
- # 06/12/93 SBR Created
- #########################################################################
- task _select(theDesc, exact := false, notErrors := {}, v_level := 4)
- begin
- global gCurrentError;
-
- if gCurrentError begin
- RIncomplete("_select: current error ({gCurrentError}) - did not try select",v_level);
- return false;
- end;
-
- if exact select theDesc!;
- else select theDesc;
-
- theError := ErrorHandler(ScriptError(), notErrors, v_level);
- if theError[1]
- theSelect := false;
- else theSelect := true;
-
- if R_BeVerbose(v_level) begin
- if not theSelect
- RIncomplete("_select: Error ({theError}) selecting {theDesc}",v_level);
- else RStatus("_select: Selected {theDesc}",v_level);
- end;
-
- return theSelect;
- end;
-
-
- #########################################################################
- # task _type(keyList, codeList, pad, notErrors, v_level)
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # Description: Type a list of keys and/or character codes. If target crashed,
- # always return false until gCurrentError is reset.
- # Parameters: keyList: the keys to type
- # codeList: the character codes to type
- # pad: use or do not use the keyPad
- # notErrors: passed to ErrorHandler
- # v_level: verbosity level for reporting
- # Returns: true/false for success/failure
- # NOTE: As of VU 2.0.1, the real type does not return a value
- # Examples: if not _type({returnKey},{20},{-1170})[2] println "Typing failed";
- # Assumptions: VU 2.0.1
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # History:
- # 06/12/93 SBR Created
- #########################################################################
- task _type( keyList := {}, codeList := {}, pad := undefined, notErrors := {},
- v_level := 4 )
- begin
- global gCurrentError;
-
- if gCurrentError begin
- RIncomplete("_type: current error ({gCurrentError}) - did not try typing",v_level);
- return false;
- end;
-
- if isUndefined(pad) begin
- if codeList
- if keyList type c:codeList k:keyList;
- else type c:codeList;
- else type k:keyList;
- end;
- else begin
- if codeList
- if keyList type c:codeList k:keyList p:pad;
- else type c:codeList p:pad;
- else type k:keyList p:pad;
- end;
-
- theError := ErrorHandler(ScriptError(), notErrors, v_level);
- if theError[1]
- theType := false;
- else theType := true;
-
- if R_BeVerbose(v_level) begin
- typeString := "c:{codeList} k:{keyList} p:{pad}";
- if not theType
- RIncomplete("_type: Error ({theError}) typing {typeString}",v_level);
- else RStatus("_type: Typed {typeString}",v_level);
- end;
-
- return theType;
- end;
-
-
- #########################################################################
- # task _pressKey(keyList, codeList, pad, notErrors, v_level)
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # Description: Press a list of keys and/or character codes. If target crashed,
- # always return false until gCurrentError is reset.
- # Parameters: keyList: the keys to press
- # codeList: the character codes to press
- # pad: use or do not use the keyPad
- # notErrors: passed to ErrorHandler
- # v_level: verbosity level for reporting
- # Returns: true/false for success/failure
- # NOTE: As of VU 2.0.1, the real pressKey does not return a value
- # Examples: if not _pressKey({shiftKey},{20},{-1170}) println "pressKey failed";
- # Assumptions: VU 2.0.1
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # History:
- # 06/12/93 SBR Created
- #########################################################################
- task _pressKey( keyList := {}, codeList := {}, pad := undefined, notErrors := {},
- v_level := 4)
- begin
- global gCurrentError;
-
- if gCurrentError begin
- RIncomplete("_pressKey: current error ({gCurrentError}) - did not try pressing",v_level);
- return false;
- end;
-
- if isUndefined(pad) begin
- if codeList
- if keyList pressKey c:codeList k:keyList;
- else pressKey c:codeList;
- else pressKey k:keyList;
- end;
- else begin
- if codeList
- if keyList pressKey c:codeList k:keyList p:pad;
- else pressKey c:codeList p:pad;
- else pressKey k:keyList p:pad;
- end;
-
- theError := ErrorHandler(ScriptError(), notErrors, v_level);
- if theError[1]
- thePressKey := false;
- else thePressKey := true;
-
- if R_BeVerbose(v_level) begin
- pressKeyString := "c:{codeList} k:{keyList} p:{pad}";
- if not thePressKey
- RIncomplete("_pressKey: Error ({theError}) pressing {thepressKeyString}",v_level);
- else RStatus("_pressKey: Pressed {thepressKeyString}",v_level);
- end;
-
- return thePressKey;
- end;
-
-
- #########################################################################
- # task _releaseKey(keyList, codeList, notErrors, v_level)
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # Description: Release a list of keys and/or character codes. If target crashed,
- # always return false until gCurrentError is reset.
- # Parameters: keyList: the keys to release
- # codeList: the character codes to release
- # notErrors: passed to ErrorHandler
- # pad: use or do not use the keyPad
- # v_level: verbosity level for reporting
- # Returns: true/false for success/failure
- # NOTE: As of VU 2.0.1, the real releaseKey does not return a value
- # Examples: if not _releaseKey({shiftKey},{20},{-1170}) println "releaseKey failed";
- # Assumptions: VU 2.0.1
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # History:
- # 06/12/93 SBR Created
- #########################################################################
- task _releaseKey( keyList := {}, codeList := {}, pad := undefined, notErrors := {},
- v_level := 4)
- begin
- global gCurrentError;
-
- if gCurrentError begin
- RIncomplete("_releaseKey: current error ({gCurrentError}) - did not try releasing",v_level);
- return false;
- end;
-
- if isUndefined(pad) begin
- if codeList
- if keyList releaseKey c:codeList k:keyList;
- else releaseKey c:codeList;
- else releaseKey k:keyList;
- end;
- else begin
- if codeList
- if keyList releaseKey c:codeList k:keyList p:pad;
- else releaseKey c:codeList p:pad;
- else releaseKey k:keyList p:pad;
- end;
-
- theError := ErrorHandler(ScriptError(), notErrors, v_level);
- if theError[1]
- theReleaseKey := false;
- else theReleaseKey := true;
-
- if R_BeVerbose(v_level) begin
- releaseKeyString := "c:{codeList} k:{keyList} p:{pad}";
- if not theReleaseKey
- RIncomplete("_releaseKey: Error ({theError}) releasing {releaseKeyString}",v_level);
- else RStatus("_releaseKey: Released {releaseKeyString}",v_level);
- end;
-
- return theReleaseKey;
- end;
-
-
- #########################################################################
- # task E_InitializeErrors(v_level)
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # Description: Set up an associate list in the global variable gErrorVectorTable for
- # all known possible error values. Each item in the list is
- # { error, { taskRef, info, v_level } }
- # error: an error code from ScriptError() or any other value
- # taskRef:
- # zero: no task to call, only a string to return
- # task reference: call when this error occurs, return string
- # info: (taskRef = 0): the string associated with this error
- # (taskRef <> 0): the parameter list for the task reference
- # You can temporarily substitute your own handler(s) by using the tasks
- # EPushHandler() and EPopHandler(). For your custom handler the error
- # item can be an integer or any other error value you want to trap.
- # The taskRef item can be zero or a task reference.
- # Your handler must return an error string explaining what happened.
- # Parameters: v_level: Verbosity level for reporting.
- # Returns: true if setup worked, false if not
- # Examples: E_InitializeErrors();
- # Assumptions: VU 2.0.1
- #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
- # History:
- # 06/12/93 SBR Created
- #########################################################################
- task E_InitializeErrors(v_level := 4)
- begin
- global gCurrentError, gPreviousErrorStack, gErrorVectorTable, gUserErrorVectorTable,
- gErrorsAreInitialized;
-
- gErrorsAreInitialized := false;
- gCurrentError := {};
- gPreviousErrorStack := {};
- gUserErrorVectorTable := {};
- gErrorVectorTable :=
- {
- { 0, { 0,"no error",0 } },
- { -1, { 0,"some unknown error",0 } },
- { -2, { 0,"VU program error (not a script error)",0 } },
- { -1000,{ 0,"overflow",0 } },
- { -1001,{ 0,"underflow",0 } },
- { -1002,{ 0,"string too long",0 } },
- { -1003,{ 0,"invalid operand type",0 } },
- { -1004,{ 0,"invalid trait value",0 } },
- { -1100,{ 0,"target failure",0 } },
- { -1101,{ 0,"no descriptor available",0 } },
- { -1102,{ 0,"invalid descriptor type",0 } },
- { -1103,{ 0,"invalid argument to commands",0 } },
- { -1104,{ 0,"no target available",0 } },
- { -1105,{ 0,"match failure",0 } },
- { -1106,{ 0,"command action failed",0 } },
- { -1107,{ 0,"no key equivalent available for menu item",0 } },
- { -1120,{ 0,"drag failed - destination off bounds",0 } },
- { -1130,{ 0,"size/close/zoom failed - window inactive",0 } },
- { -1140,{ 0,"size failed - new size off bounds",0 } },
- { -1150,{ 0,"scroll failed - position off bounds",0 } },
- { -1160,{ 0,"type/press/release keyboard operation failed",0 } },
- { -1170,{ 0,"mouse operation failed",0 } },
- { -1200,{ 0,"bad parameter to task call",0 } },
- { -1210,{ 0,"Gestalt not available on target",0 } },
- { -1220,{ 0,"no such pending external tool call",0 } },
- { -1221,{ 0,"no such service for external tool",0 } },
- { -1222,{ 0,"no such external tool",0 } },
- { -1223,{ 0,"launch of external tool failure",0 } },
- { -1230,{ 0,"could not find application with that signature (creator code)",0 } },
- { -1231,{ 0,"could not launch application due to error",0 } }
- };
- theError := ScriptError();
- if not theError begin
- gErrorsAreInitialized := true;
- return RStatus("E_InitializeErrors: Error system is initialized.", v_level);
- end;
- return RIncomplete("E_InitializeErrors: ScriptError returned {theError}", v_level);
- end;
-
-